package com.example.mydemo.controller.hc;


import com.example.mydemo.model.tableVO;
import com.example.mydemo.service.impl.LogService;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.*;


import java.util.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author syf
 * @since 2025-05-28
 */
@RestController
@RequestMapping("/log")
public class LogController {

    @Autowired
    private LogService logService;

    @Autowired
    private MongoTemplate mongoTemplate;

//    @Autowired
//    private IMenuService iMenuService;
//    @Autowired
//    private MenuMapper menuMapper;
//    @GetMapping("/getMenuById")
//    @ResponseBody
//    public ResponseDTO<Menu> getList(@RequestParam Long id) {
//        Menu sysParam = menuMapper.selectOne(new QueryWrapper<Menu>().eq("menu_id", id).eq("is_delete", 0));
//        if (sysParam.getIsDelete()==0L){
//            return new ResponseDTO<>(200, "获取信息成功！", sysParam);
//        }else {
//            return new ResponseDTO<>(200, "获取信息失败！", sysParam);
//        }
//    }
    @GetMapping("/getlogpage")
    public tableVO getlogpage(@RequestParam Long page, @RequestParam Long limit,@RequestParam(defaultValue = "") String className) {
//        Page<LogBean> codepage = new Page<>(page, limit); // 创建分页对象，当前页为1，每页显示5条记录
//        Pageable pageable = PageRequest.of(page.intValue(), limit.intValue());
        tableVO a = new tableVO();

        Map<String,Object> sysParamPagePage;
        if(StringUtil.isNullOrEmpty(className)){
            sysParamPagePage = logService.getLogsByPage("","",Math.toIntExact(page), Math.toIntExact(limit));

        }else{
            sysParamPagePage = logService.getLogsByPage("className",className, Math.toIntExact(page), Math.toIntExact(limit));
        }
        List<Object> logs= new ArrayList<>();
        for(Object n :Arrays.asList(sysParamPagePage.get("data"))){
            logs= (List<Object>) n;
        }
            a.setCode(0L);
            a.setMsg("");
            a.setData(logs);
            Long total  = (long) sysParamPagePage.get("count");
            a.setCount(total);
            return a;
    }
}
